﻿using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

namespace Kratos.Framework.ContentManagement.Models.SystemRights
{
    public class MenuPermission : EntityBase
    {
        public MenuPermission()
        {
            Children = new List<MenuPermission>();
        }

        public virtual string ActionName { get; set; }

        public virtual string ControllerName { get; set; }

        public virtual string ActionDescription { get; set; }

        public virtual string ControllerDescription { get; set; }

        public virtual string PrevIcon { get; set; }

        public virtual string iconCls { get { return PrevIcon; } }

        public virtual string MenuName { get; set; }

        public virtual string text { get { return MenuName; } }

        public virtual int? ParentId { get; set; }

        public virtual bool Leaf
        {
            get { return this.Children.Count() <= 0; }
        }

        public virtual string Url { get; set; }

        public virtual IEnumerable<MenuPermission> Children { get; set; }

        private int? _level;
        public virtual int? NodeLevel
        {
            get
            {
                if (_level != null && _level.Value > 2)
                    throw new Exception("系统不支持2级以上的菜单");
                return _level;
            }
            set { _level = value; }
        }

        public virtual bool Enabled { get; set; }
    }
}
